import java.io.Serializable;
import java.util.Iterator;
import java.util.LinkedList;

import javax.swing.JOptionPane;
import javax.swing.JTextArea;

/**
 * This class is for class details
 */
public class Cls implements Serializable {
	
	public Cls() {
		super();
	}

	private String classID;
	private String className;
	
	public Cls(String ID, String name) {
		
		classID = ID;
		className = name;
	}

	public Cls(String id) {
		this.className = DBname(id);
		classID = id;
	}

	/**
	 * @return the classID
	 */
	public String getClassID() {
		return classID;
	}

	/**
	 * @param classID the classID to set
	 */
	public void setClassID(String classID) {
		this.classID = classID;
	}

	/**
	 * @return the className
	 */
	public String getClassName() {
		return className;
	}

	/**
	 * @param className the className to set
	 */
	public void setClassName(String className) {
		this.className = className;
	}
	public String DBname(String id)
	{
		SQL s = new SQL(id, 26);
		s.accept();
		return (String)s.getMsg();
	}
	public LinkedList<ClassInCourse> DBclassInCourse()
	{
		SQL s = new SQL(this.classID,47);
		s.accept();
		LinkedList<ClassInCourse> list = (LinkedList<ClassInCourse>)s.getMsg();
		Iterator<ClassInCourse> itr = list.iterator();
		while (itr.hasNext())
			if (!itr.next().getClassID().equals(this.classID))
			 itr.remove();
		return list;		
	}
	public LinkedList<StudentList> DBstudentList()
	{
		SQL s = new SQL(this.classID,98);
		s.accept();
		LinkedList<StudentList> list = (LinkedList<StudentList>)s.getMsg();
		Iterator<StudentList> itr = list.iterator();
		while (itr.hasNext())
		{
			StudentList SL = itr.next();
			if ((!SL.getlID().equals(this.classID))||(SL.getType()!=3))
			 itr.remove();
		}
		return list;		
	} 
	
	public void DBSHOW()
	{
		System.out.println("Now Classes data should show");
		
		LinkedList<ClassInCourse> listCIC = DBclassInCourse();
		LinkedList<StudentList>   listSL  = DBstudentList();
		Iterator<ClassInCourse>   itrCIC  = listCIC.iterator();
		Iterator<StudentList>     itrSL   = listSL.iterator();
		System.out.println("size of list CTC: "+listCIC.size());
	
		
		String output = "";
		if (!itrCIC.hasNext()) output += "There are no courses for this class\n";
		else
		{
			output +="Here are the courses and teachers "+this.className+" has\n";
			while (itrCIC.hasNext())
			{
				ClassInCourse CIC = itrCIC.next();
				output += "Course: "+CIC.getCourseID()+" Teacher: "+CIC.getTeacherID()+"\n";
			
				if (!itrSL.hasNext()) output += " There are no students in this class\n";
				else
				{
					output += "here are the students in this class\n";
					while (itrSL.hasNext())
					{
						StudentList SL = itrSL.next();
						output += SL.getsID()+"  ";
					}
				}
			}
		}
		JTextArea outputArea = new JTextArea( 11, 60 );
		outputArea.setText( output );

		JOptionPane.showMessageDialog( null, outputArea,"Class Data",JOptionPane.INFORMATION_MESSAGE );
		
		
	}
	public void histo(String[] columnHeader, int[] avalues, int ahistogramHeight, int amaxColumnWidth){
		Histogram H = new Histogram(columnHeader, avalues, ahistogramHeight,amaxColumnWidth);
		
	}
	
}
